<template>
    <view>
        <!-- pages/site/addsite/index.wxml -->
        <view class="moudle bg-white radius margin-lr-sm padding-lr-sm box-sizing padding-tb flexs align-center text-df margin-top-sm">
            <view class="margin-right-sm">门店名称</view>
            <input class="flex-sub" :value="name" @input="getname" placeholder="店名+地标 例：沙宣美发（大冲店）" maxlength="10" />
        </view>
        <view class="moudle bg-white radius margin-lr-sm padding-lr-sm box-sizing padding-tb flexs align-center text-df margin-top-sm">
            <view class="margin-right-sm">选择地区</view>
            <view class="flexs justify-between flex-sub">
                <view :class="'text-df ' + (city ? '' : 'text-darkGrey')" @tap="showmolde">{{ city ? city : '请选择地区' }}</view>
                <!-- <view bindtap="getLocation" class="centers">
      <van-icon name="location-o" color="#FF8722" />
    </view> -->
            </view>
        </view>
        <view class="moudle bg-white radius margin-lr-sm padding-lr-sm box-sizing padding-tb flexs align-start text-df margin-top-sm">
            <view class="margin-right-sm">详细地址</view>
            <textarea
                class="flex-sub text-df"
                :value="address"
                @input="getaddress"
                style="height: 200rpx"
                placeholder="请填写详细地址"
                placeholder-style="font-size:14px;"
            ></textarea>
        </view>
        <view class="bar_btn radiues text-center bg-orange margin-top-sm text-lg text-bold" @tap="onAdd">提交审核</view>
        <van-popup :show="show" position="bottom" @close="onClose">
            <van-area :area-list="areaList" :columns-num="3" title="选择城市" @cancel="onClose" @confirm="onFirm" />
        </van-popup>
    </view>
</template>

<script>
import picker from '@/component/picker/picker';
// pages/site/addsite/index.js
const app = getApp(); // 引入app

const _request = require('../../../utils/request.js'); // 引入require
// 引入SDK核心类，js文件根据自己业务，位置可自行放置

var QQMapWX = require('../../../utils/qqmap-wx-jssdk.min.js');

var qqmapsdk;

const area = require('../../../utils/area');

export default {
    components: {
        picker
    },
    data() {
        return {
            show: false,
            areaList: area.areaList,
            name: '',
            city: '',
            address: ''
        };
    },
    methods: {
        getname(e) {
            this.setData({
                name: e.detail.value
            });
        },

        getaddress(e) {
            this.setData({
                address: e.detail.value
            });
        },

        showmolde() {
            this.setData({
                show: true
            });
        },

        onClose() {
            this.setData({
                show: false
            });
        },

        onFirm(e) {
            console.log(e);
            this.setData({
                show: false,
                city: e.detail.values.map((item) => {
                    return item.name;
                })
            });
        },

        // 授权定位权限
        // getLocation() {
        //   var _this = this
        //   wx.chooseLocation({
        //     success:function(res){
        //       _this.setData({
        //         city:res.address,
        //         address:res.name
        //       })
        //     }
        //   })
        // },
        onAdd() {
            if (!this.name) {
                uni.showToast({
                    title: '请输入门店名称',
                    icon: 'none'
                });
                return;
            }

            if (!this.city) {
                uni.showToast({
                    title: '请选择地区',
                    icon: 'none'
                });
                return;
            }

            if (!this.address) {
                uni.showToast({
                    title: '请输入详细地址',
                    icon: 'none'
                });
                return;
            }

            var authinfo = app.globalData.authinfo;

            _request
                .postObj('/storeAuthApply/save', {
                    realname: authinfo.realname,
                    cardno: authinfo.cardno,
                    licenseno: authinfo.licenseno,
                    businesslicensePath: authinfo.businesslicensePath,
                    bannerPath: authinfo.bannerPath,
                    storephotosPaths: authinfo.storephotosPaths,
                    handIDcardPath: authinfo.handIDcardPath,
                    storeId: uni.getStorageSync('storeId')
                })
                .then((res) => {
                    if (res.data.code == 200) {
                        uni.showToast({
                            title: '上传成功',
                            icon: 'none'
                        });
                        setTimeout(() => {
                            uni.switchTab({
                                url: '/firstpages/home/index'
                            });
                        }, 2000);
                    }
                });
        }
    }
};
</script>
<style>
page {
    background: #f5f5f5;
}
.moudle {
    width: 710rpx;
    box-shadow: 2px 2px 8px 2px rgba(241, 241, 241, 0.4);
}
.bar_btn {
    width: 670rpx;
    line-height: 90rpx;
    position: fixed;
    bottom: 60rpx;
    left: 40rpx;
}
</style>
